<?php
/*
 * @version $Id$
 -------------------------------------------------------------------------
 GLPI - Gestionnaire Libre de Parc Informatique
 Copyright (C) 2003-2014 by the INDEPNET Development Team.

 http://indepnet.net/   http://glpi-project.org
 -------------------------------------------------------------------------

 LICENSE

 This file is part of GLPI.

 GLPI is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 GLPI is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with GLPI. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
 */

/** @file
* @brief
*/
include ('../inc/includes.php');
if (empty($_GET["id"])) {
   $_GET["id"] = "";
}
//资产实例化
$assetsmange = new Assetsmange();
if (empty($_GET["id"]) && isset($_GET["asset_name"])) {
    $assetsmange->getFromDBbyName($_GET["asset_name"]);
    Html::redirect($CFG_GLPI["root_doc"]."/front/assetsmange.form.php?id=".$assetsmange->fields['id']);
}
if (empty($_GET["asset_name"])) {
    $_GET["asset_name"] = "";
}
//资产增加
if (isset($_POST["add"])) {
    $assetsmange->check(-1, 'w', $_POST);
    $now=date("Y-m-d H:i:s");
    $_POST['create_time']=$now;
    $_POST['update_now']=$now;
   // Pas de nom pas d'ajout
   if (!empty($_POST["asset_name"]) && $newID=$assetsmange->add($_POST)) {
      Event::log($newID, "assetsmanges", 4, "setup",
                 sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["asset_name"]));
   }
   Html::back();
}
//资产删除
else if (isset($_POST["delete"])) {
    $assetsmange->check($_POST['id'], 'd');
    $assetsmange->delete($_POST);
    Event::log($_POST["id"], "assetsmanges", 4, "setup",
              //TRANS: %s is the user login
              sprintf(__('%s deletes an item'), $_SESSION["glpiname"]));
    $assetsmanges->redirectToList();

}
//资产更新
else if (isset($_POST["update"])) {
    $assetsmange->check($_POST['id'], 'w');
    $now=date("Y-m-d H:i:s");
    $_POST['update_now']=$now;
    $assetsmange->update($_POST);
    Event::log($_POST['id'], "assetsmanges", 5, "setup",
              //TRANS: %s is the user login
              sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
    Html::back();
} else {
   if (isset($_GET["ext_auth"])) {
      Html::header(Assetsmange::getTypeName(2), '', "admin", "assetsmange");
      User::showAddExtAuthForm();
      Html::footer();
   } else if (isset($_POST['add_ext_auth_ldap'])) {
      Session::checkRight("import_externalauth_users", "w");
      if (isset($_POST['login']) && !empty($_POST['login'])) {
         AuthLdap::importUserFromServers(array('name' => $_POST['login']));
      }
      Html::back();
   } else if (isset($_POST['add_ext_auth_simple'])) {
         if (isset($_POST['login']) && !empty($_POST['login'])) {
            Session::checkRight("import_externalauth_users", "w");
            $input = array('name'     => $_POST['login'],
                           '_extauth' => 1,
                           'add'      => 1);
            $user->check(-1, 'w', $input);
            $newID = $user->add($input);
            Event::log($newID, "assetsmange", 4, "setup",
                       sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"],
                               $_POST["login"]));
         }

         Html::back();
   } else {
      Session::checkRight("assetsmange", "r");
      Html::header(Assetsmange::getTypeName(2), '', "admin", "assetsmange");
      $assetsmange->showForm($_GET["id"]);
      Html::footer();
   }
}
?>